#coding:utf8
'''输入城市，输出天气情况'''
import gzip
import urllib
import urllib2
import json
import gzip
from StringIO import StringIO


city = raw_input('输入要查询的城市：')
try:
    url = 'http://wthrcdn.etouch.cn/weather_mini?city=%s' % city
    request = urllib2.Request(url)
    response = urllib2.urlopen(request)
    if response.info().get('Content-Encoding') == 'gzip':
        buf = StringIO(response.read())
        f = gzip.GzipFile(fileobj = buf)
        text = f.read()
    text = json.loads(text)
    today = text['data']['forecast'][0]

except:
    print '输入的城市不存在'
else:

    '''重新编码为utf8'''
    city = text['data']['city'].encode('utf8')
    type = today['type'].encode('utf8')
    fengxiang = today['fengxiang'].encode('utf8')
    high = today['high'].encode('utf8')
    low = today['low'].encode('utf8')
    print '%s,%s,%s,%s,%s' % (city,type,fengxiang,high,low)
